package com.hd.crdao.view;

import android.content.Context;
import android.content.res.TypedArray;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.EditText;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.hd.crdao.R;

/**
 *
 *@author Programming
 *@date 2017/5/19 0019
 */

public class ExpandTextView extends RelativeLayout {


    ImageView mUserHeadPic;
    FrameLayout mImagelayout;
    public EditText mEtRight;
    public ImageView mRightArrow;
    public TextView mTvLeft;
    public TextView mTvRight;

    public ExpandTextView(Context context) {
        this(context, null);
    }

    public ExpandTextView(Context context, AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public ExpandTextView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);

        View view = LayoutInflater.from(context).inflate(R.layout.explandtextview, this, true);
        mTvLeft = (TextView) view.findViewById(R.id.tvleft);
        mEtRight = (EditText) view.findViewById(R.id.etright);
        mImagelayout = (FrameLayout) view.findViewById(R.id.imagelayout);
        mUserHeadPic = (ImageView) view.findViewById(R.id.user_head_pic);
        mRightArrow = (ImageView) view.findViewById(R.id.right_arrow);
        mTvRight = (TextView) view.findViewById(R.id.tvright);

        TypedArray attributes = context.obtainStyledAttributes(attrs, R.styleable.ExpandTextView);


        String lefttext = attributes.getString(R.styleable.ExpandTextView_lefttext);
        String rightText = attributes.getString(R.styleable.ExpandTextView_righttext);
        boolean arrow_displays = attributes.getBoolean(R.styleable.ExpandTextView_arrow_isdisplay, false);
        boolean headpic_displays = attributes.getBoolean(R.styleable.ExpandTextView_headpic_isdisplay, false);
        boolean right_checkable = attributes.getBoolean(R.styleable.ExpandTextView_righttext_checkable, false);
        boolean right_singleline = attributes.getBoolean(R.styleable.ExpandTextView_righttext_isSingleline, false);
        boolean righttextdisplay = attributes.getBoolean(R.styleable.ExpandTextView_righttext_display, false);
        boolean rightedittextdisplay = attributes.getBoolean(R.styleable.ExpandTextView_rightedittext_display, false);


        attributes.recycle();

        mTvLeft.setText(lefttext);
        mTvRight.setText(rightText);
        if (arrow_displays) {
            mRightArrow.setVisibility(View.VISIBLE);
        } else {
            mRightArrow.setVisibility(View.GONE);
        }
        if (headpic_displays) {
            mImagelayout.setVisibility(View.VISIBLE);
            mUserHeadPic.setVisibility(View.VISIBLE);
        } else {
            mImagelayout.setVisibility(View.GONE);
            mUserHeadPic.setVisibility(View.GONE);
        }
        if (right_checkable) {
            mEtRight.setEnabled(false);
        } else {
            mEtRight.setEnabled(true);
        }

        if (right_singleline) {
            mEtRight.setSingleLine(true);

        } else {
            mEtRight.setSingleLine(false);
        }

        if (rightedittextdisplay) {
            mEtRight.setVisibility(View.VISIBLE);
        } else {
            mEtRight.setVisibility(View.GONE);
        }

        if (righttextdisplay) {
            mTvRight.setVisibility(View.VISIBLE);
        } else {
            mTvRight.setVisibility(View.GONE);
        }

    }

    public EditText getEtRight() {
        return mEtRight;
    }

    public void setEtRight(EditText etRight) {
        mEtRight = etRight;
    }

    public FrameLayout getImagelayout() {
        return mImagelayout;
    }

    public void setImagelayout(FrameLayout imagelayout) {
        mImagelayout = imagelayout;
    }

    public ImageView getRightArrow() {
        return mRightArrow;
    }

    public void setRightArrow(ImageView rightArrow) {
        mRightArrow = rightArrow;
    }

    public TextView getTvLeft() {
        return mTvLeft;
    }

    public void setTvLeft(TextView tvLeft) {
        mTvLeft = tvLeft;
    }

    public TextView getTvRight() {
        return mTvRight;
    }

    public void setTvRight(TextView tvRight) {
        mTvRight = tvRight;
    }

    public ImageView getUserHeadPic() {
        return mUserHeadPic;
    }

    public void setUserHeadPic(ImageView userHeadPic) {
        mUserHeadPic = userHeadPic;
    }
}
